< previous page page_818 next page >

Page 818
Using the UPDATE Statement
The UPDATE statement is another action query. It is used to change the values of specific fields in a table. The syntax of the UPDATE statement is as follows:
UPDATE tablename SET field = newvalue [WHERE clause]
You can update multiple fields in a table at one time by listing multiple field = newvalue clauses, separated by commas. The inclusion of the WHERE clause is optional. If it is excluded, all records in the table are changed.
Listing C.19 shows two examples of the UPDATE statement. The first example changes the salesperson ID for a group of customers, as happens when a salesperson leaves the company and his or her accounts are transferred to someone else. The second example changes the retail price of all retail sales items, as can be necessary to cover increased operating costs.
Listing C.19 UPDATE.TXTUsing the UPDATE Statement to Change Field Values for Many Records at Once
'*******************************************
'Change the SalesID for a group of customers
'*******************************************
UPDATE Customers SET SalesID = 'EGREEN' WHERE SalesID='JBURNS'
'******************************************************
'Increase the retail price of all items by five percent
'******************************************************
UPDATE [Retail Items] SET Retail = Retail * 1.05
Using Data-Definition-Language Statements
Data-definition-language statements (DDLs) let you create, modify, and delete tables and indexes in a database with a single statement. For many situations, these statements take the place of the data-access-object methods described in Chapter 24, "Database Design and Normalization." However, there are some limitations to using the DDL statements. The main limitation is that these statements are supported only for Jet databases (remember that data-access objects can be used for any database accessed with the Jet engine). The other limitation of DDL statements is that they support only a small subset of the properties of the table, field, and index objects. If you need to specify properties outside of this subset, you must use the methods described in Chapter 24.
Defining Tables with DDL Statements
Three DDL statements are used to define tables in a database:
CREATE TABLEDefines a new table in a database
ALTER TABLEChanges a table's structure
DROP TABLEDeletes a table from the database

 
< previous page page_818 next page >